declare interface MenuItem {
  label: string;
  href?: string;
  key?: string;
  iconName?: string;
  children?: MenuItem[]
}

const rawMenu: Array<MenuItem> = [
  {
    "label": "仪表盘",
    "href": "/dashboard",
    "iconName": "DashboardOutlined",
  },
  {
    "label": "任务列表",
    "href": "/index/task_list",
    "iconName": "ScheduleOutlined",
  },

]

import SparkMD5 from 'spark-md5'

function processMenu(list: Array<MenuItem> = []) {
  for (let i = 0; i < list.length; i++) {
    let item = list[i];
    if (item.href) {
      item['key'] = SparkMD5.hash(item.href)
    } else {
      item['key'] = SparkMD5.hash(String(i))
    }
    let cl = item.children;
    if (cl) {
      item.children = processMenu(cl);
    }
  }
  return list;
}

export const menuList = processMenu(rawMenu)

export const getPathKey = (path: string) => SparkMD5.hash(path)
